/* 审核状态操作 */
$(function() {
  $(".state-btn").click(function() {
	var self = $(this);
	var url = this.href;
	var dataObj = $(this).data();
	//alert(dataObj.status);
	var val = $(this).data('id');
	var od = $(this).attr('od');//原始数据
	var ud = $(this).attr('ud');//更新数据
	var status = $(this).attr('status');
	var isRefresh = $(this).attr('refresh') == 'true' ? true : false;
	if (status == 0) {
	  var upstatus = 1;
	} else {
	  var upstatus = 0;
	}
	  $.ajax({
		cache: true,
		dataType:'json',
		type: "POST",
		url:url,
		data:_PK_+'='+val+'&onlyup=1&is_json=1&status='+upstatus,
		async: false,
		error: function(request) {
		  //showMessage('系统繁忙',2000);
			art.dialog({
			  time: 2,
			  content: '系统繁忙'
			});
		},
		success: function(data) {
		  if (data.status) {
			if (status == 0) {
			  var btn_color = 'btn-yellow';
			  var nstatus = 1;
			  // var ajax_url = _URL_ + '/edit';
			} else {
			  var btn_color = 'btn-danger';
			  var nstatus = 0;
			  // var ajax_url = _URL_ + '/edit';
			}
			// self.attr('href', ajax_url);
			var b = '<button class="btn btn-minier ' + btn_color + '">' + ud + '</button>';
			$('#item_' + val).html(b);
			self.attr('od', ud);
			self.attr('ud', od);
			self.attr('title', od);
			self.attr('status', nstatus);
			//jumpUrl(data.url || 'self');
			if(data.url){
				jumpUrl(data.url);
			}else if(isRefresh){
				location.reload();
			}
			return false;
		  } else {
			//window.alert(data.info, { icon: 5 });
			$.dialog.alert(data.msg);
		  }
		}
	  });
	return false;
	
  });
});

$(function() {
	//通用打开窗口
	$('.layopen').each(function(){
		$(this).click(function(){
			layopen(this);
		});
	});
});
//打开信息窗口
function layopen(obj){
	var url = $(obj).attr('url');
	if(!url){
		return;
	}
	var btn = $(obj).attr('btn')=='false' ? false : true;
	var title = $(obj).attr('title');
	var width = $(obj).attr('data-width') || '95%';
	var height = $(obj).attr('data-height') || '100%';
	if(btn){
		layer.open({
			type: 2,
			shade: false,
			title: title, //不显示标题
			closeBtn: 1, //不显示关闭按钮
			skin: 'layui-layer-rim', //加上边框
			area: [width, height], //宽高
			btn: ['保存', '取消'],
			shift: 2,
			shadeClose: true,
			shade: 0.8,
			content: url,
			cancel: function (index) {
				layer.close(index);
			}
		});
	}else{
		layer.open({
			type: 2,
			shade: false,
			title: title, //不显示标题
			closeBtn:1, //不显示关闭按钮
			skin: 'layui-layer-rim', //加上边框
			area: [width, height], //宽高
			shift: 2,
			shadeClose: true,
			shade: 0.8,
			content: url,  
				cancel: function(index){
					layer.close(index);
					this.content.hide();
				}
			
			});
	}
}

/**
 * 图片弹出框
 *
 * .AjaxLoadImg
 */
$(document).on('click', '.js-img-dialog', function() {
  var $this = $(this);
  var title = $this.attr('title') || '详情';
  var url = $this.data('url') || this.src;
  var style = '';
  var img = '<img src="' + url + '" style="' + style + '" />';

	layer.open({
		type: 1, // 显示图片时，type选1
		area:['auto','auto'], // 区域，auto指宽度自适应，高度设置为700px
		// area: ['1000px', '500px'],
		shade: 0.8,
		title: false, // false表示不显示标题
		maxmin: false, // true表示显示最大化和最小化
		closeBtn: 1, // 1表示显示关闭的X号，0表示不显示
		shadeClose: true,
		content: img
	});

});

//删除
function fdel(id){
  var keyValue;
  if (id)
  {
    keyValue = id;
  }else {
    keyValue = getSelectCheckboxValues();
  }
  if (!keyValue)
  {
    alert('请选择删除项！');
    return false;
  }

  if (window.confirm('删除将不可恢复，确认要删除选择项吗？'))
  {
    window.location.href = _URL_+"/fdel/"+_PK_+"/"+keyValue+"/time/"+new Date().getTime();
  }
}


//删除
function vdel(id){
  var keyValue;
  if (id)
  {
    keyValue = id;
  }else {
    keyValue = getSelectCheckboxValues();
  }
  if (!keyValue)
  {
    alert('请选择删除项！');
    return false;
  }

  if (window.confirm('确实要删除选择项吗？'))
  {
    window.location.href = _URL_+"/vdel/"+_PK_+"/"+keyValue+"/time/"+new Date().getTime();
  }
}